using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class GMBtnItem
{
    private Button btn_click;
    private TMP_Text tmp_name;
    private Action<string> onClick;
    private string name;
    private string template;

    public GMBtnItem(GMAttribute attribute, Action<string> onClick)
    {
        name = attribute.name;
        template = attribute.template;
        this.onClick = onClick;
    }

    public void BindItem(GameObject item)
    {
        btn_click = item.GetComponent<Button>();
        tmp_name = item.transform.GetChild(0).GetComponent<TMP_Text>();
        tmp_name.text = name;
        btn_click.onClick.RemoveAllListeners();
        btn_click.onClick.AddListener(() =>
        {
            onClick?.Invoke(template);
        });
    }
}
